"""
# -*- coding: utf-8 -*-
# @Time : 2023/4/16 17:08
# @Author : LTY
# @File : L231_PP_Function_Page_test.py
# @function : python3.9.2
"""

import sys

from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
from L231_PP_RSB4BQTtest_LTY_230414 import L231_PP_Beginning_Page_test as Begin
from L231_PP_RSB4BQTtest_LTY_230414 import L231_PP_PictureFunction_Page_test as Picture_Func
from L231_PP_RSB4BQTtest_LTY_230414 import L231_PP_TimeSetting_Page_test as TimeSetting_Func
from L231_PP_RSB4BQTtest_LTY_230414 import L231_PP_DishIN_Page_test as DishIN_Func
from L231_PP_RSB4BQTtest_LTY_230414 import L231_PP_DishOUT_Page_test as DishOUT_Func
from ui_QT.ui_MainPage import Ui_MainWindow as Func_ui_Main


class QT_Function(QMainWindow):

    def __init__(self, parent=None):
        super().__init__(parent)  # 调用父类构造函数，创建窗体
        self.ui_Func = Func_ui_Main()  # 创建UI对象
        self.ui_Func.setupUi(self)  # 构造UI界面
        self.initUI()

##  ==============自定义功能函数========================
    def initUI(self):
        self.setWindowTitle('主页面')

        # 退出登录按钮设置
        self.button_exit = self.ui_Func.pushButton_exit
        self.button_exit.clicked.connect(self.EXIT)
        self.button_exit.setShortcut("Esc")

        # 各个页面设置
        self.TimeSetting_page = TimeSetting_Func.QT_TimeSetting()
        self.DishIN_page = DishIN_Func.QT_DishIN()
        self.Picture_page = Picture_Func.QT_PictureFunction()
        self.DishOUT_page = DishOUT_Func.QT_DishOUT()

        self.ui_Func.mainlayout.addWidget(self.TimeSetting_page)
        self.ui_Func.mainlayout.addWidget(self.DishIN_page)
        self.ui_Func.mainlayout.addWidget(self.Picture_page)
        self.ui_Func.mainlayout.addWidget(self.DishOUT_page)

        self.TimeSetting_page.hide()
        self.DishIN_page.hide()
        self.Picture_page.hide()
        self.DishOUT_page.hide()

        # 模式按钮设置
        self.button1 = self.ui_Func.pushButton_mode1
        self.button1.clicked.connect(self.TurnOnMode1)
        self.button2 = self.ui_Func.pushButton_mode2
        self.button2.clicked.connect(self.TurnOnMode2)
        self.button3 = self.ui_Func.pushButton_mode3
        self.button3.clicked.connect(self.TurnOnMode3)
        self.button4 = self.ui_Func.pushButton_mode4
        self.button4.clicked.connect(self.TurnOnMode4)

    def EXIT(self):
        reply = QMessageBox.warning(self, '退出登录', '您确定退出登录吗？', QMessageBox.No | QMessageBox.No, QMessageBox.Yes)
        if reply == QMessageBox.Yes:
            self.ui_Begin = Begin.QT_Begin()
            self.close()
            self.ui_Begin.show()
        elif reply == QMessageBox.No:
            QMessageBox.close()

    @pyqtSlot()
    def TurnOnMode1(self):
        self.TimeSetting_page.show()
        self.DishIN_page.hide()
        self.Picture_page.hide()
        self.DishOUT_page.hide()
        self.close()

    @pyqtSlot()
    def TurnOnMode2(self):
        self.TimeSetting_page.hide()
        self.DishIN_page.hide()
        self.Picture_page.hide()
        self.DishOUT_page.show()
        self.close()

    @pyqtSlot()
    def TurnOnMode3(self):
        self.TimeSetting_page.hide()
        self.DishIN_page.show()
        self.Picture_page.hide()
        self.DishOUT_page.hide()
        self.close()

    @pyqtSlot()
    def TurnOnMode4(self):
        self.TimeSetting_page.hide()
        self.DishIN_page.hide()
        self.Picture_page.show()
        self.DishOUT_page.hide()
        self.close()


##  ============窗体测试程序 ================================
if __name__ == "__main__":  # 用于当前窗体测试
    app = QApplication(sys.argv)  # 创建GUI应用程序
    app.setWindowIcon(QIcon('..\\image\\school(256).ico'))
    form = QT_Function()  # 创建窗体
    form.show()

    sys.exit(app.exec_())